package com.decent.manager.system.dao;

import com.decent.common.entity.manager.SystemBanner;
import com.decent.manager.system.dto.SystemBannerDTO;
import com.decent.manager.system.vo.SystemBannerVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author: decent Gjh
 * @date: 2022/10/24/15:53
 * @description:
 */
@Mapper
public interface SystemBannerDao {

    /**
     * 新建banner
     * @param banner banner信息
     */
    @Insert("insert into common_banner (banner_type,image_url,value,sort,create_datetime) " +
            "values (#{banner.bannerType},#{banner.imageUrl},#{banner.value},#{banner.sort},now())")
    void insertImage(@Param("banner") SystemBanner banner);

    /**
     * 更新banner
     * @param banner banner信息
     * @return 影响行数
     */
    @Update("update common_banner set banner_type = #{banner.bannerType},image_url = #{banner.imageUrl}, " +
            "value = #{banner.value},sort = #{banner.sort}, update_datetime = now()  where id = #{banner.id} ")
    int updateBanner(@Param("banner") SystemBannerDTO banner);

    /**
     * 根据id删除banner
     * @param bannerId bannerId
     * @return 删除条数
     */
    @Delete("delete from common_banner where id = #{bannerId} ")
    int deleteBanner(@Param("bannerId") int bannerId);

    /**
     * 根据id查找common_banner
     * @param bannerId id
     * @return banner信息
     */
    @Select("select image_url from common_banner where id = #{bannerId}")
    SystemBannerVO getBannerById(@Param("bannerId") int bannerId);

    /**
     * 获取所有banner 根据sort排序
     * @return banner列表
     */
    @Select("select * from common_banner order by sort")
    List<SystemBannerVO> getBannerList();
}
